/*
* Copyright 2016 Yonyou Auto Information Technology（Shanghai） Co., Ltd. All Rights Reserved.
*
* This software is published under the terms of the YONYOU Software
* License version 1.0, a copy of which has been included with this
* distribution in the LICENSE.txt file.
*
* @Project Name : marketing-service-testdriving-appointment
*
* @File name : TestdrivingAmService.java
*
* @Author : LiuJun
*
* @Date : 2016年11月07日
*
----------------------------------------------------------------------------------
*     Date       Who       Version     Comments
* 1. 2016年11月07日    LiuJun    1.0
*
*
*
*
----------------------------------------------------------------------------------
*/

package com.yonyou.gmmc.dealerApp.api.service.impl;

import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import org.apache.log4j.Logger;
import org.marketing.common.constants.BusinessConstant;
import org.marketing.common.constants.CodeConstant;
import org.marketing.common.constants.MessagePushConstant;
import org.marketing.common.dto.customerInfo.LoveModelDto;
import org.marketing.common.dto.search.DealerAppSearchDto;
import org.marketing.common.dto.showroom.PackageExhibitionDto;
import org.marketing.common.dto.testdrivingAm.TestDrivingAmDto;
import org.marketing.common.dto.testdrivingAm.TestDrivingRoutesDto;
import org.marketing.common.dto.testdrivingAm.TestdrivingAmFrecordDto;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocol;
import org.marketing.common.entity.wechatpushmessage.WeChatMessageProtocolMessageTemplateContent;
import org.marketing.common.exception.ServiceAppException;
import org.marketing.common.exception.ServiceBizException;
import org.marketing.common.util.CommonUtils;
import org.marketing.common.util.DateUtil;
import org.marketing.common.util.SerializeUtils;
import org.marketing.common.util.WeChatPushMessageUtil;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import com.github.pagehelper.PageHelper;
import com.ibm.icu.util.Calendar;
import com.yonyou.gmmc.dealerApp.api.dao.LoveModelDao;
import com.yonyou.gmmc.dealerApp.api.dao.ShowroomDao;
import com.yonyou.gmmc.dealerApp.api.dao.TtTestdriveAppointmentMapper;
import com.yonyou.gmmc.dealerApp.api.entity.LoveModelPO;
import com.yonyou.gmmc.dealerApp.api.entity.TestDrivingRoutesPO;
import com.yonyou.gmmc.dealerApp.api.entity.TestdrivingAmFrecordPO;
import com.yonyou.gmmc.dealerApp.api.entity.TestdrivingAmPO;
import com.yonyou.gmmc.dealerApp.api.service.CustomerInfoService;

/**
 * @author LiuJun 
 * 试驾预约service
 * @date 2016年11月07日
 */
@Service("testdriveAmService")
public class TestdrivingAmService {

    private Logger           logger = Logger.getLogger(TestdrivingAmService.class);

    @Autowired
    private TtTestdriveAppointmentMapper testdrivingAmDao;
    
    @Autowired
    private CustomerInfoService customerInfoApiServiceInterface;
    
//    @Autowired
//    private ShowroomApiService showroomApiServiceInterface;
    
    @Autowired
    private RabbitTemplate rabbitTemplate;

    @Autowired
    private ShowroomDao showroomDao;
    @Autowired
    private LoveModelDao loveModelDao;

    /**
    *
    * @author LiuJun
    * 试驾预约保存
    * @date 2016年11月7日
    * @param testDrivingAmDto
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public TestDrivingAmDto saveTestDrivingAppointment(TestDrivingAmDto testDrivingAmDto) throws ServiceAppException,
                                                                                          ServiceBizException {
        try {
            TestdrivingAmPO testdrivingAmPO = new TestdrivingAmPO();
            
            testDrivingAmDto.setCreateDate(new Date());
            
            testDrivingAmDto.setAppointmentStatus(CodeConstant.DRIVINGTEST_STATUS_SAVED);
            
            //设置默认来源类型
            if(CommonUtils.isNullOrO(testDrivingAmDto.getSourceType())){
                testDrivingAmDto.setSourceType(BusinessConstant.SOURCE_TYPE_WECHAT);
            }
            BeanUtils.copyProperties(testDrivingAmDto, testdrivingAmPO);

            testdrivingAmDao.insertTestDrivingAm(testdrivingAmPO);
            
            testDrivingAmDto.setTestdriveAppointmentId(testdrivingAmPO.getTestdriveAppointmentId());
            
            //保存心仪车型
            LoveModelDto loveModelDto = new LoveModelDto();
            loveModelDto.setPackageCode(testDrivingAmDto.getPackageCode());
            loveModelDto.setDealerCode(testDrivingAmDto.getDealerCode());
            loveModelDto.setPotentialUserId(testDrivingAmDto.getPotentialUserId());
            saveLoveModelDto(loveModelDto);
            
            //试驾成功后发送模板消息通知客户
            sendTemplateMsgForConfirmed(testDrivingAmDto);
            return testDrivingAmDto;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }
    /**
    *
    * @author LiuJun
    * 保存心仪车型
    * @date 2016年12月29日
    * @param loveModelDto
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    private LoveModelDto saveLoveModelDto(LoveModelDto loveModelDto) throws ServiceAppException,ServiceBizException {
        try {
            
            LoveModelPO loveModelPo = loveModelDao.queryLoveModelDataByPIdAndPackageCode(loveModelDto.getPackageCode(),loveModelDto.getPotentialUserId(),loveModelDto.getDealerCode());
            if(loveModelPo==null){
                Calendar calendar = Calendar.getInstance();
                calendar.setTime(new Date());
                
                loveModelPo = new LoveModelPO();
                BeanUtils.copyProperties(loveModelDto, loveModelPo);
                loveModelPo.setCreateDate(calendar.getTime());
                loveModelDao.insertLoveModel(loveModelPo);
            }
            loveModelDto.setLoveModelId(loveModelPo.getLoveModelId());
            
            return loveModelDto;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }

    
    /**
    *
    * @author LiuJun
    * 试驾预约发送模板消息
    * @date 2017年1月6日
    * @param testDrivingAmDto
    */
    private void sendTemplateMsgForConfirmed(TestDrivingAmDto testDrivingAmDto) {
        try{
            logger.info("sendTemplateMsg is entry");
            try{
                logger.info("saveTestDrivingAppointment-sendTemplateMsg-sendTemplateMsg="+SerializeUtils.serialize(testDrivingAmDto));
            }catch (Exception e) {
            }
            //模板消息接收人员list
            List<String> receivesList = new ArrayList<String>();
            
            receivesList.add(testDrivingAmDto.getOpenId());
            
            //设置模板消息内容
            List<WeChatMessageProtocolMessageTemplateContent> contentList = new ArrayList<WeChatMessageProtocolMessageTemplateContent>();
            WeChatMessageProtocolMessageTemplateContent content1 = new WeChatMessageProtocolMessageTemplateContent();
            content1.setKey("first");
            content1.setValue("您于"+DateUtil.formateDate(new Date(),"MM/dd")+"提交的试驾预约我们已安排");
            
            PackageExhibitionDto packageExhibitionDto = getPackageExhibitionData(testDrivingAmDto.getPackageCode(), testDrivingAmDto.getDealerCode());
            WeChatMessageProtocolMessageTemplateContent content2 = new WeChatMessageProtocolMessageTemplateContent();
            if(packageExhibitionDto!=null){
                content2.setKey("keynote1");content2.setValue(packageExhibitionDto.getPackageName());
            }else{
                content2.setKey("keynote1");content2.setValue(BusinessConstant.EMPTY_STRING);
            }

            WeChatMessageProtocolMessageTemplateContent content3 = new WeChatMessageProtocolMessageTemplateContent();
            content3.setKey("keynote2");content3.setValue(DateUtil.formateDate(testDrivingAmDto.getStartDate(), "MM/dd HH:mm"));

            WeChatMessageProtocolMessageTemplateContent content4 = new WeChatMessageProtocolMessageTemplateContent();
            content4.setKey("keynote3");content4.setValue(testDrivingAmDto.getSalesConsultantName());


            WeChatMessageProtocolMessageTemplateContent content5 = new WeChatMessageProtocolMessageTemplateContent();
            content5.setKey("remark");content5.setValue("期待您的光临，如果您不能按时到店请提前与我们联系\n您的销售顾问："+testDrivingAmDto.getSalesConsultantName()+"\n电话："+testDrivingAmDto.getSalesConsultantPhone());
            contentList.add(content1);
            contentList.add(content2);
            contentList.add(content3);
            contentList.add(content4);
            contentList.add(content5);
            //获得微信模板消息对象
            WeChatMessageProtocol weChatMessageProtocol = WeChatPushMessageUtil.getWeChatTemplate(BusinessConstant.WECHAT_TEMPLATE_TYPE_TESTDRIVE_CONFIRMED_NOTIFICATION, receivesList, contentList, testDrivingAmDto.getAuthorizerAppid(),testDrivingAmDto.getDealerCode());
            
            //插入rabbitmq消息队列
            rabbitTemplate.convertAndSend(MessagePushConstant.WECHAT_QUEUE, weChatMessageProtocol);
            logger.info("sendTemplateMsg is success");
        }catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        
    }
    /**
    *
    * @author LiuJun
    * 获取车辆配置基本信息
    * @date 2016年11月2日
    * @param packageCode
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    private PackageExhibitionDto getPackageExhibitionData(String packageCode,String dealerCode) throws ServiceAppException,
                                                                             ServiceBizException {
        
        if(CommonUtils.isNullOrEmpty(packageCode)){
            logger.warn("getPackageExhibitionData-packageCode is null");
            throw new ServiceBizException("packageCode is null");
        }
        try{
            List<PackageExhibitionDto> packageDtoList = showroomDao.queryPackageExhibitionData(packageCode,dealerCode);
            if(CommonUtils.isNullOrEmpty(packageDtoList)){
                throw new ServiceAppException("the packageCode:"+packageCode+",is not exist");
            }
            if(packageDtoList.size()>1){
                logger.warn("the packageCode:"+packageCode+",exist duplication data");
            }
            return packageDtoList.get(0);
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }


    /**
     * 
    *取得服务顾问的试驾预约信息
    * @author WangHuicheng
    * 
    * @date 2016年11月21日
    * @param dealerCode            经销商代码
    * @param salesConsultantId     服务顾问ID
    * @param status                状态
    * @param strStartDateFrom             预约到店时间FROM
    * @param strStartDateEnd             预约到店时间FROM
    * @return
     */
    public List<TestDrivingAmDto> getTestDriverInfo(String dealerCode,
                                                    Integer salesConsultantId,
                                                    Integer status,
                                                    String strStartDateFrom,
                                                    String strStartDateEnd){
        Date startDateFrom = null;
        Date startDateEnd = null;
        if (null != strStartDateFrom){
            startDateFrom = DateUtil.dataFormat(strStartDateFrom);
        }
        if (null != strStartDateEnd){
            startDateEnd  = DateUtil.dataFormat(strStartDateEnd);
        }
        List<TestDrivingAmDto> list = testdrivingAmDao.getTestDriverInfo(dealerCode, salesConsultantId, status, startDateFrom, startDateEnd);
        if (null == list){
            list = new ArrayList<TestDrivingAmDto>();
        }
        return list;
    }

    	
    /**
    *
    * @author LiuJun
    * 更新试驾预约状态
    * @date 2016年11月21日
    * @param testdrivingAmFrecordDto
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public void updateTestDrivingAppointStatus(TestdrivingAmFrecordDto testdrivingAmFrecordDto) throws ServiceAppException, ServiceBizException {
        
        if(!isExistTestDrivingAppoint(testdrivingAmFrecordDto.getTestdriveAppointmentId())){
            throw new ServiceAppException("the record is not exist:"+testdrivingAmFrecordDto.getTestdriveAppointmentId());
        }
        try {
            
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            testdrivingAmFrecordDto.setUpdateBy(testdrivingAmFrecordDto.getUserId());
            testdrivingAmFrecordDto.setUpdateDate(calendar.getTime());
            testdrivingAmDao.updateTestDrivingAppointStatus(testdrivingAmFrecordDto);
            
            //判断是否已试驾-暂定已试驾是完成状态-完成时发送模板消息-add by liujun 2017-01-17
            if(CodeConstant.DRIVINGTEST_STATUS_FINISHED == testdrivingAmFrecordDto.getAppointmentStatus()){
                sendTemplateMsgForFinished(testdrivingAmFrecordDto);
            }
            
            testdrivingAmFrecordDto.setCreateBy(testdrivingAmFrecordDto.getUserId());
            testdrivingAmFrecordDto.setCreateDate(calendar.getTime());
            if(testdrivingAmFrecordDto.getFollowDate() ==null){
                testdrivingAmFrecordDto.setFollowDate(calendar.getTime());
            }
            //试驾预约跟进表维护
            TestdrivingAmFrecordPO testdrivingAmFrecordPO = new TestdrivingAmFrecordPO();
            BeanUtils.copyProperties(testdrivingAmFrecordDto, testdrivingAmFrecordPO);
            
            //===该段代码由王会成后期添加，请后期开发人员确认是不是跟进记录只有两种状态
            if (null != testdrivingAmFrecordDto.getAppointmentStatus()
                    && CodeConstant.DRIVINGTEST_FOLLOW_STATUS_CONFIRM != testdrivingAmFrecordDto.getAppointmentStatus().intValue()){
                testdrivingAmFrecordPO.setAppointmentStatus(CodeConstant.DRIVINGTEST_FOLLOW_STATUS_FOLLOW);
            } else {
                testdrivingAmFrecordPO.setAppointmentStatus(CodeConstant.DRIVINGTEST_FOLLOW_STATUS_CONFIRM);
            }
            //===
            
            testdrivingAmDao.insertTestdrivingAmFrecord(testdrivingAmFrecordPO);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }

    }
    
    
    /**
    *
    * @author LiuJun
    * 试驾完成时发送模板消息
    * @date 2017年1月17日
    * @param testDrivingAmDto
    */
    private void sendTemplateMsgForFinished(TestdrivingAmFrecordDto testdrivingAmFrecordDto) {
        try{
            logger.info("sendTemplateMsgForFinished is entry");
            
            Long testdriveAppointmentId = testdrivingAmFrecordDto.getTestdriveAppointmentId();
            
            TestDrivingAmDto testDrivingAmDto = testdrivingAmDao.queryTestdriveAtRelevantInfoById(testdriveAppointmentId);
            //模板消息接收人员list
            List<String> receivesList = new ArrayList<String>();
            
            receivesList.add(testDrivingAmDto.getOpenId());
            
            //设置模板消息内容
            List<WeChatMessageProtocolMessageTemplateContent> contentList = new ArrayList<WeChatMessageProtocolMessageTemplateContent>();
            WeChatMessageProtocolMessageTemplateContent content1 = new WeChatMessageProtocolMessageTemplateContent();
            content1.setKey("first");
            content1.setValue("您本次的试驾服务已完成。");
            
            PackageExhibitionDto packageExhibitionDto = getPackageExhibitionData(testDrivingAmDto.getPackageCode(), testDrivingAmDto.getDealerCode());
            WeChatMessageProtocolMessageTemplateContent content2 = new WeChatMessageProtocolMessageTemplateContent();
            if(packageExhibitionDto!=null){
                content2.setKey("keynote1");content2.setValue(packageExhibitionDto.getPackageName());
            }else{
                content2.setKey("keynote1");content2.setValue(BusinessConstant.EMPTY_STRING);
            }

            WeChatMessageProtocolMessageTemplateContent content3 = new WeChatMessageProtocolMessageTemplateContent();
            content3.setKey("keynote2");content3.setValue(DateUtil.formateDate(testDrivingAmDto.getStartDate(), "MM/dd HH:mm"));

            WeChatMessageProtocolMessageTemplateContent content4 = new WeChatMessageProtocolMessageTemplateContent();
            content4.setKey("keynote3");content4.setValue(testDrivingAmDto.getSalesConsultantName());


            WeChatMessageProtocolMessageTemplateContent content5 = new WeChatMessageProtocolMessageTemplateContent();
            content5.setKey("remark");content5.setValue("感谢您对我们的信任，您的肯定是我们前行的动力，同时，我们也将竭力带给您更加周到的服务体验。");
            contentList.add(content1);
            contentList.add(content2);
            contentList.add(content3);
            contentList.add(content4);
            contentList.add(content5);
            //获得微信模板消息对象
            WeChatMessageProtocol weChatMessageProtocol = WeChatPushMessageUtil.getWeChatTemplate(BusinessConstant.WECHAT_TEMPLATE_TYPE_TESTDRIVE_FINISHED, receivesList, contentList, testDrivingAmDto.getAuthorizerAppid(),testDrivingAmDto.getDealerCode());
            
            //插入rabbitmq消息队列
            rabbitTemplate.convertAndSend(MessagePushConstant.WECHAT_QUEUE, weChatMessageProtocol);
            logger.info("sendTemplateMsgForFinished is success");
        }catch (Exception e) {
            logger.error(e.getMessage(),e);
        }
        
    }




    /**
    *
    * @author LiuJun
    * 保存试驾预约跟进记录
    * @date 2016年11月21日
    * @param testdrivingAmFrecordDto
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public TestdrivingAmFrecordDto saveTestDrivingAppointFrecord(TestdrivingAmFrecordDto testdrivingAmFrecordDto) throws ServiceAppException,
                                                                                                                  ServiceBizException {
        if(!isExistTestDrivingAppoint(testdrivingAmFrecordDto.getTestdriveAppointmentId())){
            throw new ServiceAppException("the record is not exist:"+testdrivingAmFrecordDto.getTestdriveAppointmentId());
        }
        try{
            Calendar calendar = Calendar.getInstance();
            calendar.setTime(new Date());
            
            testdrivingAmFrecordDto.setCreateBy(testdrivingAmFrecordDto.getUserId());
            testdrivingAmFrecordDto.setCreateDate(calendar.getTime());
            TestdrivingAmFrecordPO testdrivingAmFrecordPO = new TestdrivingAmFrecordPO();
            
            BeanUtils.copyProperties(testdrivingAmFrecordDto, testdrivingAmFrecordPO);
            
            
            
            if (CodeConstant.DRIVINGTEST_FOLLOW_STATUS_CONFIRM != testdrivingAmFrecordDto.getAppointmentStatus().intValue()){
                testdrivingAmFrecordPO.setAppointmentStatus(CodeConstant.DRIVINGTEST_FOLLOW_STATUS_FOLLOW);
            } else {
                testdrivingAmFrecordPO.setAppointmentStatus(CodeConstant.DRIVINGTEST_FOLLOW_STATUS_CONFIRM);
            }
            testdrivingAmDao.insertTestdrivingAmFrecord(testdrivingAmFrecordPO);
            
            testdrivingAmFrecordDto.setTlTestdriverRecodeId(testdrivingAmFrecordPO.getTlTestdriverRecodeId());
            
            return testdrivingAmFrecordDto;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }

    }
    
    
    /**
    *
    * @author LiuJun
    * 判断是否存在试驾预约记录
    * @date 2016年11月23日
    * @param testdriveAppointmentId
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    
    public boolean isExistTestDrivingAppoint(Long testdriveAppointmentId) throws ServiceAppException,
                                                                          ServiceBizException {
        try{
            long count = testdrivingAmDao.queryTestDrivingAppointCount(testdriveAppointmentId);
            
            if(count>0){
                return true;
            }
            return false;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }

    }

    /**
    *
    * @author QianKun
    * 试驾查询列表
    * @date 2016年11月16日
    * @param potentialUserId
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public List<TestDrivingAmDto> getTestDrivingData(Long potentialUserId,String phone,String submitDateFrom,String submitDateEnd,String startDateFrom,String startDateEnd,String appointmentStatus) throws ServiceAppException,
                                                                           ServiceBizException {
        try {
            //PageHelper.startPage(BusinessConstant.CURRENT_PAGE,BusinessConstant.PAGE_SIZE);
            List<TestDrivingAmDto> dtoList = testdrivingAmDao.queryTestDrivingData(potentialUserId,phone,submitDateFrom,submitDateEnd,startDateFrom,startDateEnd,appointmentStatus);          
            return dtoList;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }
    
    /**
    *
    * @author QianKun
    * 试驾查询详情
    * @date 2016年11月15日
    * @param testdriveAppointmentId
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public List<TestDrivingAmDto> getTestDrivingDataById(String testdriveAppointmentId) throws ServiceAppException,
                                                                                      ServiceBizException {
        try {
            List<TestDrivingAmDto> dtoList = testdrivingAmDao.queryTestDrivingDataById(testdriveAppointmentId);
            return dtoList;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }
    
    
    /**
     * 
    * 取得试乘试驾预约信息
    * @author WangHuicheng
    * @date 2016年11月25日
    * @param dealerAppSearchDto
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
     */
    public List<TestDrivingAmDto> getTestDriverInfoList(DealerAppSearchDto dealerAppSearchDto)throws ServiceAppException,
                                                                                                       ServiceBizException {
        
        try{
            PageHelper.startPage(dealerAppSearchDto.getPageNo(),BusinessConstant.PAGE_SIZE);
            List<TestDrivingAmDto> list = testdrivingAmDao.getTestDriverInfoList(dealerAppSearchDto) ;
            return list;
        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
        
    }

    
    /**
     * 
    * 驾驶路线
    * @author WangHuicheng
    * @date 2016年11月30日
    * @param testDrivingRoutesDto
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
     */
    public List<TestDrivingRoutesDto> getTestDriverRoutes(TestDrivingRoutesDto testDrivingRoutesDto) throws ServiceAppException,
                                                                                                     ServiceBizException {
        List<TestDrivingRoutesDto> list = testdrivingAmDao.getTestDriverRoutes(testDrivingRoutesDto);

        return list;
    }
    
    
    /**
     * 更新试乘试驾信息(抢客户)
    *
    * @author WangHuicheng
    * @date 2016年12月14日
    * @param testDrivingAmDto
    * @throws ServiceAppException
    * @throws ServiceBizException
     */
    public void updateTestdrivingAm4rush(TestDrivingAmDto testDrivingAmDto) throws ServiceAppException, ServiceBizException {
        try {
            TestdrivingAmPO testdrivingAmPO = new TestdrivingAmPO();

            testDrivingAmDto.setUpdateDate(new Date());

            BeanUtils.copyProperties(testDrivingAmDto, testdrivingAmPO);

            testdrivingAmDao.updateTestdrivingAm4rush(testdrivingAmPO);

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }


    /**
    *
    * @author LiuJun
    * 获取试驾路线
    * @date 2016年12月30日
    * @param dealerCode
    * @return
    * @throws ServiceAppException
    * @throws ServiceBizException
    */
    public List<TestDrivingRoutesDto> getTestDrivingRoutes(String dealerCode) throws ServiceAppException,
                                                                              ServiceBizException {
        List<TestDrivingRoutesDto> routesDtoList = null;
        TestDrivingRoutesDto testDrivingRoutesDto = null;
        try {
            List<TestDrivingRoutesPO> poList = testdrivingAmDao.queryTestDrivingRoutesByDealerCode(dealerCode);
            if(CommonUtils.isNullOrEmpty(poList)){
                return routesDtoList;
            }
            routesDtoList = new ArrayList<TestDrivingRoutesDto>();
            for(TestDrivingRoutesPO routesPo:poList){
                testDrivingRoutesDto = new TestDrivingRoutesDto();
                BeanUtils.copyProperties(routesPo, testDrivingRoutesDto);
                routesDtoList.add(testDrivingRoutesDto);
                
            }
            return routesDtoList;

        } catch (Exception e) {
            logger.error(e.getMessage(), e);
            throw new ServiceAppException(e.getMessage(), e);
        }
    }
}
